Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.sling.jackrabbit.usermanager.impl.post;
import  org.osgi.service.component.ComponentContext;

Base class for servlets manipulating users
public abstract class AbstractUserPostServlet extends
    private static final long serialVersionUID = -8401210711297654453L;

    
To be used for the encryption. E.g. for passwords in javax.jcr.SimpleCredentials.getPassword() SimpleCredentials}

Scr.property:
valueRef="DEFAULT_PASSWORD_DIGEST_ALGORITHM"
    private static final String PROP_PASSWORD_DIGEST_ALGORITHM = "password.digest.algorithm";
    private static final String DEFAULT_PASSWORD_DIGEST_ALGORITHM = "sha1";
    private String passwordDigestAlgoritm = null;
    // ---------- SCR Integration ----------------------------------------------
    protected void activate(ComponentContext context) {
        super.activate(context);
        Dictionary<?, ?> props = context.getProperties();
        Object propValue = props.get();
        if (propValue instanceof String) {
             = (StringpropValue;
        } else {
        }
    }
    protected void deactivate(ComponentContext context) {
        super.deactivate(context);
         = null;
    }

    
Digest the given password using the configured digest algorithm

Parameters:
pwd the value to digest
Returns:
the digested value
Throws:
IllegalArgumentException
    protected String digestPassword(String pwdthrows IllegalArgumentException {
        return digestPassword(pwd);
    }

    
Digest the given password using the given digest algorithm

Parameters:
pwd the value to digest
digest the digest algorithm to use for digesting
Returns:
the digested value
Throws:
IllegalArgumentException
    protected String digestPassword(String pwdString digestthrows IllegalArgumentException {
        try {
            StringBuffer password = new StringBuffer();
            password.append("{").append(digest).append("}");
            password.append(Text.digest(digestpwd.getBytes("UTF-8")));
            return password.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalArgumentException(e.toString());
        } catch (UnsupportedEncodingException e) {
            throw new IllegalArgumentException(e.toString());
        }
    }
New to GrepCode? Check out our FAQ X