Commit fe7e5831 authored by Misagh Moayyed's avatar Misagh Moayyed
Browse files

removed deprecated concepts

parent 3b2cb428
/*
* Licensed to Apereo under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Apereo 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 the following location:
*
* 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.jasig.cas.authentication.handler;
import org.jasig.cas.authentication.RootCasException;
import javax.validation.constraints.NotNull;
/**
* The most generic type of authentication exception that one can catch if not
* sure what specific implementation will be thrown. Top of the tree of all
* other AuthenticationExceptions.
*
* @author Scott Battaglia
* @since 4.2.0
*/
public abstract class AbstractAuthenticationException extends RootCasException {
/** Serializable ID. */
private static final long serialVersionUID = 3906648604830611762L;
private static final String DEFAULT_TYPE = "error";
/** The error type that provides additional info about the nature of the exception cause. **/
private final String type;
/**
* Instantiates a new authentication exception.
*
* @param code the code
*/
public AbstractAuthenticationException(final String code) {
this(code, "", DEFAULT_TYPE);
}
/**
* Instantiates a new authentication exception.
*
* @param code the code
* @param msg the msg
*/
public AbstractAuthenticationException(final String code, final String msg) {
this(code, msg, DEFAULT_TYPE);
}
/**
* @param type The type of the error message that caused the exception to be thrown. By default,
* all errors are considered of <code>error</code>.
* @param code the exception code
* @param msg the error message
*/
public AbstractAuthenticationException(final String code, final String msg, @NotNull final String type) {
super(code, msg);
this.type = type;
}
/**
* @param code the exception code
* @param throwable the exception that originally caused the authentication failure
*/
public AbstractAuthenticationException(final String code, final Throwable throwable) {
super(code, throwable);
this.type = DEFAULT_TYPE;
}
/**
* Method to return the error type of this exception.
*
* @return the String identifier for the cause of this error.
*/
public final String getType() {
return this.type;
}
}
/*
* Licensed to Apereo under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Apereo 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 the following location:
*
* 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.jasig.cas.authentication;
import org.jasig.cas.authentication.handler.AbstractAuthenticationException;
import org.jasig.cas.authentication.handler.NamedAuthenticationHandler;
import org.jasig.cas.authentication.principal.UsernamePasswordCredentials;
import javax.security.auth.login.FailedLoginException;
import javax.validation.constraints.NotNull;
import java.security.GeneralSecurityException;
/**
* Adapts a CAS 3.x {@link org.jasig.cas.authentication.handler.AuthenticationHandler} onto a CAS 4.x
* {@link AuthenticationHandler}.
*
* @author Marvin S. Addison
* @since 4.0.0
*/
public class LegacyAuthenticationHandlerAdapter implements AuthenticationHandler {
/** Wrapped CAS 3.0 authentication handler. */
@NotNull
private final org.jasig.cas.authentication.handler.AuthenticationHandler legacyHandler;
/** Adapts CAS 4.0 credentials onto CAS 3.0 credentials. */
@NotNull
private final CredentialsAdapter credentialsAdapter;
/**
* Creates a new instance that adapts the given legacy authentication handler.
*
* @param legacy CAS 3.0 authentication handler.
*/
public LegacyAuthenticationHandlerAdapter(final org.jasig.cas.authentication.handler.AuthenticationHandler legacy) {
if (!legacy.supports(new UsernamePasswordCredentials())) {
throw new IllegalArgumentException(
"Cannot infer credential conversion strategy - specify CredentialsAdapter explicitly.");
}
this.legacyHandler = legacy;
this.credentialsAdapter = new UsernamePasswordCredentialsAdapter();
}
/**
* Creates a new instance that adapts the given legacy authentication handler.
* Use this form for a handler that supports a credential type other than username/password credentials.
*
* @param legacy CAS 3.0 authentication handler.
* @param adapter Adapts CAS 4.0 credential onto 3.0 credential.
*/
public LegacyAuthenticationHandlerAdapter(
final org.jasig.cas.authentication.handler.AuthenticationHandler legacy,
final CredentialsAdapter adapter) {
this.legacyHandler = legacy;
this.credentialsAdapter = adapter;
}
@Override
public HandlerResult authenticate(final Credential credential) throws GeneralSecurityException, PreventedException {
try {
if (this.legacyHandler.authenticate(credentialsAdapter.convert(credential))) {
final CredentialMetaData md;
if (credential instanceof CredentialMetaData) {
md = (CredentialMetaData) credential;
} else {
md = new BasicCredentialMetaData(credential);
}
return new DefaultHandlerResult(this, md);
} else {
throw new FailedLoginException(
String.format("%s failed to authenticate %s", this.getName(), credential));
}
} catch (final AbstractAuthenticationException e) {
throw new GeneralSecurityException(
String.format("%s failed to authenticate %s", this.getName(), credential), e);
}
}
@Override
public boolean supports(final Credential credential) {
return this.legacyHandler.supports(credentialsAdapter.convert(credential));
}
@Override
public String getName() {
if (this.legacyHandler instanceof NamedAuthenticationHandler) {
return ((NamedAuthenticationHandler) this.legacyHandler).getName();
} else {
return this.legacyHandler.getClass().getSimpleName();
}
}
}
/*
* Licensed to Apereo under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Apereo 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 the following location:
*
* 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.jasig.cas.authentication.handler;
import org.jasig.cas.authentication.principal.Credentials;
/**
* Deprecated interface for authenticating user-supplied credential. This component has
* been superseded by {@link org.jasig.cas.authentication.AuthenticationHandler} as of
* CAS 4.0.
* <p>
* Validate Credential support for AuthenticationManagerImpl.
* <p>
* Determines that Credential are valid. Password-based credential may be
* tested against an external LDAP, Kerberos, JDBC source. Certificates may be
* checked against a list of CA's and do the usual chain validation.
* Implementations must be parameterized with their sources of information.
* <p>
* Callers to this class should first call supports to determine if the
* AuthenticationHandler can authenticate the credential provided.
*
* @author Scott Battaglia
* @deprecated In favor of {@link org.jasig.cas.authentication.AuthenticationHandler}.
* @since 3.0.0
* @see org.jasig.cas.authentication.LegacyAuthenticationHandlerAdapter
* @see org.jasig.cas.authentication.AuthenticationHandler
*/
@Deprecated
public interface AuthenticationHandler {
/**
* Method to determine if the credential supplied are valid.
*
* @param credential The credential to validate.
* @return true if valid, return false otherwise.
* @throws AbstractAuthenticationException An AbstractAuthenticationException can contain
* details about why a particular authentication request failed.
*/
boolean authenticate(Credentials credential)
throws AbstractAuthenticationException;
/**
* Method to check if the handler knows how to handle the credential
* provided. It may be a simple check of the Credential class or something
* more complicated such as scanning the information contained in the
* Credential object.
*
* @param credential The credential to check.
* @return true if the handler supports the Credential, false othewrise.
*/
boolean supports(Credentials credential);
}
/*
* Licensed to Apereo under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Apereo 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 the following location:
*
* 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.jasig.cas.authentication.handler;
/**
* Named variant of CAS 3.0 {@link AuthenticationHandler} interface. This is deprecated in favor of
* {@link org.jasig.cas.authentication.AuthenticationHandler}.
*
* @author Scott Battaglia
* @deprecated The CAS 4.0 {@link org.jasig.cas.authentication.AuthenticationHandler} provides support for named
* handlers, which makes this interface redundant.
* @since 3.2.1
*
*/
@Deprecated
public interface NamedAuthenticationHandler extends AuthenticationHandler {
/**
* Gets the name of this handler.
*
* @return the name
*/
String getName();
}
......@@ -1352,7 +1352,6 @@
<module>cas-server-support-generic</module>
<module>cas-server-support-jdbc</module>
<module>cas-server-support-ldap</module>
<module>cas-server-support-legacy</module>
<module>cas-server-support-openid</module>
<module>cas-server-support-wsfederation</module>
<module>cas-server-support-radius</module>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment