org.apache.jetspeed.security.impl.UserManagerImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jetspeed-security Show documentation
Show all versions of jetspeed-security Show documentation
Jetspeed-2 Security Components
The newest version!
/*
* 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.jetspeed.security.impl;
import org.apache.jetspeed.Jetspeed;
import org.apache.jetspeed.components.portletpreferences.PortletPreferencesProvider;
import org.apache.jetspeed.security.AuthenticatedUser;
import org.apache.jetspeed.security.AuthenticatedUserImpl;
import org.apache.jetspeed.security.GroupManager;
import org.apache.jetspeed.security.JetspeedPrincipal;
import org.apache.jetspeed.security.JetspeedPrincipalAssociationType;
import org.apache.jetspeed.security.JetspeedPrincipalQueryContext;
import org.apache.jetspeed.security.JetspeedPrincipalType;
import org.apache.jetspeed.security.JetspeedSubjectFactory;
import org.apache.jetspeed.security.PasswordCredential;
import org.apache.jetspeed.security.PrincipalsSet;
import org.apache.jetspeed.security.RoleManager;
import org.apache.jetspeed.security.SecurityException;
import org.apache.jetspeed.security.User;
import org.apache.jetspeed.security.UserCredential;
import org.apache.jetspeed.security.UserManager;
import org.apache.jetspeed.security.UserResultList;
import org.apache.jetspeed.security.spi.JetspeedPrincipalAccessManager;
import org.apache.jetspeed.security.spi.JetspeedPrincipalStorageManager;
import org.apache.jetspeed.security.spi.UserPasswordCredentialManager;
import org.apache.jetspeed.security.spi.UserSubjectPrincipalsProvider;
import org.apache.jetspeed.security.spi.UserSubjectPrincipalsResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.security.auth.Subject;
import java.security.Principal;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
*
* Implementation for managing users and provides access to the {@link User}.
*
*
* @author David Le Strat
* @author Vivek Kumar
* @version $Id: UserManagerImpl.java 1685182 2015-06-12 22:30:03Z taylor $
*/
public class UserManagerImpl extends BaseJetspeedPrincipalManager implements UserManager, UserSubjectPrincipalsProvider
{
private static final long serialVersionUID = 2811398259474293885L;
private static final Logger log = LoggerFactory.getLogger(UserManagerImpl.class);
private String anonymousUser = "guest";
private JetspeedPrincipalType roleType;
private JetspeedPrincipalType groupType;
private UserPasswordCredentialManager credentialManager;
private RoleManager roleManager;
private GroupManager groupManager;
private Map usprMap = new HashMap();
public UserManagerImpl(JetspeedPrincipalType principalType, JetspeedPrincipalType roleType, JetspeedPrincipalType groupType,
JetspeedPrincipalAccessManager jpam, JetspeedPrincipalStorageManager jpsm, UserPasswordCredentialManager credentialManager)
{
super(principalType, jpam, jpsm);
this.credentialManager = credentialManager;
this.roleType = roleType;
this.groupType = groupType;
}
public void checkInitialized()
{
if (groupManager == null)
{
groupManager = (GroupManager) getPrincipalManagerProvider().getManager(groupType);
}
if (roleManager == null)
{
roleManager = (RoleManager) getPrincipalManagerProvider().getManager(roleType);
}
}
public User addUser(String username) throws SecurityException
{
return addUser(username, true);
}
public User addUser(String username, boolean mapped) throws SecurityException
{
User user = newUser(username, mapped);
super.addPrincipal(user, null);
if (log.isDebugEnabled())
log.debug("Added user: " + username);
return user;
}
public String getAnonymousUser()
{
return anonymousUser;
}
public PasswordCredential getPasswordCredential(User user) throws SecurityException
{
if (credentialManager != null)
{
return credentialManager.getPasswordCredential(user);
}
return null;
}
public Subject getSubject(User user) throws SecurityException
{
if (!getAnonymousUser().equals(user.getName()) && credentialManager != null)
{
PasswordCredential pwc = getPasswordCredential(user);
if (pwc != null)
{
UserCredential credential = new UserCredentialImpl(pwc);
HashSet