View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  
21  package org.apache.directory.server.kerberos.changepwd.protocol;
22  
23  
24  import org.apache.directory.server.i18n.I18n;
25  import org.apache.directory.server.kerberos.changepwd.io.ChangePasswordDecoder;
26  import org.apache.mina.core.buffer.IoBuffer;
27  import org.apache.mina.core.session.IoSession;
28  import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
29  import org.apache.mina.filter.codec.ProtocolDecoderOutput;
30  
31  
32  /**
33   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34   */
35  public class MinaChangePasswordDecoder extends CumulativeProtocolDecoder
36  {
37      private int maxObjectSize = 16384; // 16KB
38  
39  
40      /**
41       * Returns the allowed maximum size of the object to be decoded.
42       * 
43       * @return The max object size.
44       */
45      public int getMaxObjectSize()
46      {
47          return maxObjectSize;
48      }
49  
50  
51      /**
52       * Sets the allowed maximum size of the object to be decoded.
53       * If the size of the object to be decoded exceeds this value, this
54       * decoder will throw a {@link IllegalArgumentException}.  The default
55       * value is <tt>16384</tt> (16KB).
56       * 
57       * @param maxObjectSize The maximum size for a PDU
58       */
59      public void setMaxObjectSize( int maxObjectSize )
60      {
61          if ( maxObjectSize <= 0 )
62          {
63              throw new IllegalArgumentException( I18n.err( I18n.ERR_634, maxObjectSize ) );
64          }
65  
66          this.maxObjectSize = maxObjectSize;
67      }
68  
69  
70      @Override
71      protected boolean doDecode( IoSession session, IoBuffer in, ProtocolDecoderOutput out ) throws Exception
72      {
73          boolean isTcp = !session.getTransportMetadata().isConnectionless();
74  
75          out.write( ChangePasswordDecoder.decode( in.buf(), isTcp ) );
76  
77          return true;
78      }
79  }