| /* |
| * 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.directory.server.changepw.service; |
| |
| |
| import javax.naming.NamingException; |
| import javax.security.auth.kerberos.KerberosPrincipal; |
| |
| import org.apache.directory.server.changepw.exceptions.ChangePasswordException; |
| import org.apache.directory.server.changepw.exceptions.ErrorType; |
| import org.apache.directory.server.kerberos.shared.messages.components.Authenticator; |
| import org.apache.directory.server.kerberos.shared.store.PrincipalStore; |
| import org.apache.mina.common.IoSession; |
| import org.apache.mina.handler.chain.IoHandlerCommand; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| |
| /** |
| * An {@link IoHandlerCommand} for storing the new password. |
| * |
| * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> |
| * @version $Rev$, $Date$ |
| */ |
| public class ProcessPasswordChange implements IoHandlerCommand |
| { |
| /** the log for this class */ |
| private static final Logger log = LoggerFactory.getLogger( ProcessPasswordChange.class ); |
| |
| private String contextKey = "context"; |
| |
| |
| public void execute( NextCommand next, IoSession session, Object message ) throws Exception |
| { |
| ChangePasswordContext changepwContext = ( ChangePasswordContext ) session.getAttribute( getContextKey() ); |
| |
| PrincipalStore store = changepwContext.getStore(); |
| Authenticator authenticator = changepwContext.getAuthenticator(); |
| String newPassword = changepwContext.getPassword(); |
| KerberosPrincipal clientPrincipal = authenticator.getClientPrincipal(); |
| |
| // usec and seq-number must be present per MS but aren't in legacy kpasswd |
| // seq-number must have same value as authenticator |
| // ignore r-address |
| |
| try |
| { |
| String principalName = store.changePassword( clientPrincipal, newPassword ); |
| log.debug( "Successfully modified principal {}", principalName ); |
| } |
| catch ( NamingException ne ) |
| { |
| log.warn( ne.getMessage(), ne ); |
| throw new ChangePasswordException( ErrorType.KRB5_KPASSWD_SOFTERROR, ne.getExplanation().getBytes() ); |
| } |
| catch ( Exception e ) |
| { |
| log.error( "Unexpected exception.", e ); |
| throw new ChangePasswordException( ErrorType.KRB5_KPASSWD_HARDERROR ); |
| } |
| |
| next.execute( session, message ); |
| } |
| |
| |
| protected String getContextKey() |
| { |
| return ( this.contextKey ); |
| } |
| } |