forked from apache/sling-old-svn-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SLING-3227 - FormLoginModulePlugin does not work with Oak
Add FormLoginModule based on Oak support for JAAS authentication -- FormAuthenticationHandler would use FormLoginModule or FormLoginModulePlugin depending on support for Oak LoginModule. This would enable use of same bundle in both Oak and JR2 based Sling deployments -- For JAAS auth the handler would construct a FormCrendentials instance which is supported by FormLoginModule only. Once validated it would make use of Oak pre auth support to let Oak complete the JAAS login git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1649302 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
6 changed files
with
334 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
bundles/auth/form/src/main/java/org/apache/sling/auth/form/impl/jaas/FormCredentials.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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.sling.auth.form.impl.jaas; | ||
|
||
import javax.jcr.Credentials; | ||
|
||
public class FormCredentials implements Credentials { | ||
private final String userId; | ||
private final String authData; | ||
|
||
public FormCredentials(String userId, String authData) { | ||
this.userId = userId; | ||
this.authData = authData; | ||
} | ||
|
||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
public String getAuthData() { | ||
return authData; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
bundles/auth/form/src/main/java/org/apache/sling/auth/form/impl/jaas/FormLoginModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* 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.sling.auth.form.impl.jaas; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
import javax.jcr.Credentials; | ||
import javax.jcr.SimpleCredentials; | ||
import javax.security.auth.login.LoginException; | ||
|
||
import org.apache.jackrabbit.oak.spi.security.authentication.AbstractLoginModule; | ||
import org.apache.jackrabbit.oak.spi.security.authentication.PreAuthenticatedLogin; | ||
import org.apache.sling.auth.form.impl.FormAuthenticationHandler; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
final class FormLoginModule extends AbstractLoginModule { | ||
private static final Logger log = LoggerFactory.getLogger(FormLoginModule.class); | ||
|
||
/** | ||
* The set of supported credentials. required by the {@link org.apache.jackrabbit.oak.spi.security.authentication.AbstractLoginModule} | ||
*/ | ||
private static final Set<Class> SUPPORTED_CREDENTIALS = Collections.<Class>singleton(FormCredentials.class); | ||
private static final char[] EMPTY_PWD = new char[0]; | ||
|
||
/** | ||
* Extracted userId during login call. | ||
*/ | ||
private String userId; | ||
|
||
@Override | ||
protected Set<Class> getSupportedCredentials() { | ||
return SUPPORTED_CREDENTIALS; | ||
} | ||
|
||
/** | ||
* The {@link org.apache.sling.auth.form.impl.FormAuthenticationHandler} used to validate the credentials | ||
* and its contents. | ||
*/ | ||
private final FormAuthenticationHandler authHandler; | ||
|
||
FormLoginModule(FormAuthenticationHandler authHandler) { | ||
this.authHandler = authHandler; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public boolean login() throws LoginException { | ||
Credentials credentials = getCredentials(); | ||
if (credentials instanceof FormCredentials) { | ||
FormCredentials cred = (FormCredentials) credentials; | ||
userId = cred.getUserId(); | ||
|
||
if (!authHandler.isValid(cred)){ | ||
log.debug("Invalid credentials"); | ||
return false; | ||
} | ||
|
||
if (userId == null) { | ||
log.debug("Could not extract userId/credentials"); | ||
} else { | ||
// we just set the login name and rely on the following login modules to populate the subject | ||
sharedState.put(SHARED_KEY_PRE_AUTH_LOGIN, new PreAuthenticatedLogin(userId)); | ||
sharedState.put(SHARED_KEY_CREDENTIALS, new SimpleCredentials(userId, EMPTY_PWD)); | ||
sharedState.put(SHARED_KEY_LOGIN_NAME, userId); | ||
log.debug("login succeeded with trusted user: {}", userId); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public boolean commit() throws LoginException { | ||
if (userId == null) { | ||
// login attempt in this login module was not successful | ||
clearState(); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
protected void clearState() { | ||
userId = null; | ||
super.clearState(); | ||
} | ||
} |
Oops, something went wrong.