001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020 021package org.apache.directory.server.kerberos.changepwd.protocol; 022 023 024import org.apache.directory.server.i18n.I18n; 025import org.apache.directory.server.kerberos.changepwd.io.ChangePasswordDecoder; 026import org.apache.mina.core.buffer.IoBuffer; 027import org.apache.mina.core.session.IoSession; 028import org.apache.mina.filter.codec.CumulativeProtocolDecoder; 029import org.apache.mina.filter.codec.ProtocolDecoderOutput; 030 031 032/** 033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 034 */ 035public class MinaChangePasswordDecoder extends CumulativeProtocolDecoder 036{ 037 private int maxObjectSize = 16384; // 16KB 038 039 040 /** 041 * Returns the allowed maximum size of the object to be decoded. 042 * 043 * @return The max object size. 044 */ 045 public int getMaxObjectSize() 046 { 047 return maxObjectSize; 048 } 049 050 051 /** 052 * Sets the allowed maximum size of the object to be decoded. 053 * If the size of the object to be decoded exceeds this value, this 054 * decoder will throw a {@link IllegalArgumentException}. The default 055 * value is <tt>16384</tt> (16KB). 056 * 057 * @param maxObjectSize The maximum size for a PDU 058 */ 059 public void setMaxObjectSize( int maxObjectSize ) 060 { 061 if ( maxObjectSize <= 0 ) 062 { 063 throw new IllegalArgumentException( I18n.err( I18n.ERR_634, maxObjectSize ) ); 064 } 065 066 this.maxObjectSize = maxObjectSize; 067 } 068 069 070 @Override 071 protected boolean doDecode( IoSession session, IoBuffer in, ProtocolDecoderOutput out ) throws Exception 072 { 073 boolean isTcp = !session.getTransportMetadata().isConnectionless(); 074 075 out.write( ChangePasswordDecoder.decode( in.buf(), isTcp ) ); 076 077 return true; 078 } 079}