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 */ 020package org.apache.directory.api.ldap.extras.controls.ppolicy; 021 022 023/** 024 * A simple {@link PasswordPolicy} Control implementation. 025 * 026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 027 * @version $Rev$, $Date$ 028 */ 029public class PasswordPolicyImpl implements PasswordPolicy 030{ 031 /** The criticality of this {@link Control} */ 032 private boolean criticality; 033 034 /** The password policy response component if this is a response control */ 035 private PasswordPolicyResponse response; 036 037 038 /** 039 * Creates a new instance of a PasswordPolicy request Control without any 040 * response data associated with it. 041 */ 042 public PasswordPolicyImpl() 043 { 044 response = null; 045 } 046 047 048 /** 049 * Creates a new instance of a PasswordPolicy request Control without any 050 * response data associated with it. 051 * 052 * @param hasResponse A flag set to <tt>true</tt> if the control should have a response 053 */ 054 public PasswordPolicyImpl( boolean hasResponse ) 055 { 056 if ( hasResponse ) 057 { 058 response = new PasswordPolicyResponseImpl(); 059 } 060 else 061 { 062 response = null; 063 } 064 } 065 066 067 /** 068 * Creates a new instance of PasswordPolicy response Control with response 069 * information packaged into the control. 070 * 071 * @param response The encapsulated response 072 */ 073 public PasswordPolicyImpl( PasswordPolicyResponse response ) 074 { 075 this.response = response; 076 } 077 078 079 /** 080 * {@inheritDoc} 081 */ 082 @Override 083 public String getOid() 084 { 085 return PasswordPolicy.OID; 086 } 087 088 089 /** 090 * {@inheritDoc} 091 */ 092 @Override 093 public boolean isCritical() 094 { 095 return criticality; 096 } 097 098 099 /** 100 * {@inheritDoc} 101 */ 102 @Override 103 public void setCritical( boolean isCritical ) 104 { 105 this.criticality = isCritical; 106 } 107 108 109 /** 110 * 111 * {@inheritDoc} 112 */ 113 @Override 114 public void setResponse( PasswordPolicyResponse response ) 115 { 116 this.response = response; 117 } 118 119 120 /** 121 * {@inheritDoc} 122 */ 123 @Override 124 public boolean hasResponse() 125 { 126 return response != null; 127 } 128 129 130 /** 131 * 132 * {@inheritDoc} 133 */ 134 @Override 135 public PasswordPolicyResponse setResponse( boolean hasResponse ) 136 { 137 PasswordPolicyResponse old = this.response; 138 139 if ( hasResponse ) 140 { 141 this.response = new PasswordPolicyResponseImpl(); 142 } 143 else 144 { 145 this.response = null; 146 } 147 148 return old; 149 } 150 151 152 /** 153 * {@inheritDoc} 154 */ 155 @Override 156 public PasswordPolicyResponse getResponse() 157 { 158 return response; 159 } 160 161 162 /** 163 * Get a String representation of a PasswordPolicyImpl 164 * 165 * @return A BindResponse String 166 */ 167 @Override 168 public String toString() 169 { 170 StringBuilder sb = new StringBuilder(); 171 172 sb.append( " PasswordPolicy[" ); 173 sb.append( "criticality:" ).append( criticality ).append( "] " ); 174 175 if ( response != null ) 176 { 177 sb.append( response ); 178 } 179 else 180 { 181 sb.append( '\n' ); 182 } 183 184 return sb.toString(); 185 } 186}