Permalink
Browse files

SWITCHYARD-1895: Investigate changing the class name of org.switchyar…

…d.security.principal.Group
  • Loading branch information...
1 parent 2912f9b commit 230ca01f30aac27e65e2eeebabab3a50c4bf1d68 @errantepiphany errantepiphany committed with kcbabo Jan 21, 2014
@@ -13,7 +13,7 @@
*/
package org.switchyard.security.context;
-import static org.switchyard.security.principal.Group.ROLES;
+import static org.switchyard.security.principal.GroupPrincipal.ROLES;
import java.security.Principal;
import java.security.acl.Group;
@@ -23,7 +23,7 @@
import org.switchyard.security.credential.ConfidentialityCredential;
import org.switchyard.security.credential.Credential;
import org.switchyard.security.credential.PrincipalCredential;
-import org.switchyard.security.principal.User;
+import org.switchyard.security.principal.UserPrincipal;
/**
* ServletRequestCredentialExtractor.
@@ -53,7 +53,7 @@ public ServletRequestCredentialExtractor() {}
}
String remoteUser = request.getRemoteUser();
if (remoteUser != null) {
- credentials.add(new PrincipalCredential(new User(remoteUser), true));
+ credentials.add(new PrincipalCredential(new UserPrincipal(remoteUser), true));
}
String charsetName = source.getCharacterEncoding();
AuthorizationHeaderCredentialExtractor ahce;
@@ -32,9 +32,9 @@
import org.switchyard.common.lang.Strings;
import org.switchyard.security.BaseSecurityMessages;
import org.switchyard.security.callback.CertificateCallback;
-import org.switchyard.security.principal.Group;
-import org.switchyard.security.principal.Role;
-import org.switchyard.security.principal.User;
+import org.switchyard.security.principal.GroupPrincipal;
+import org.switchyard.security.principal.RolePrincipal;
+import org.switchyard.security.principal.UserPrincipal;
import org.switchyard.security.pull.KeyStorePuller;
/**
@@ -98,22 +98,22 @@ public boolean commit() throws LoginException {
String userName = _verifiedCallerCertificate.getSubjectX500Principal().getName();
// get the CN from the DN.
userName = userName.substring(userName.indexOf('=') + 1, userName.indexOf(','));
- User authenticatedPrincipal = new User(userName);
+ UserPrincipal authenticatedPrincipal = new UserPrincipal(userName);
principals.add(authenticatedPrincipal);
// maybe add roles
Properties rolesProperties = getRolesProperties();
if (rolesProperties != null) {
- Set<Group> groups = getSubject().getPrincipals(Group.class);
+ Set<GroupPrincipal> groups = getSubject().getPrincipals(GroupPrincipal.class);
Set<String> roleNames = Strings.uniqueSplitTrimToNull(rolesProperties.getProperty(userName), ",");
for (String roleName : roleNames) {
- Role role = new Role(roleName);
+ RolePrincipal role = new RolePrincipal(roleName);
if (groups.isEmpty()) {
- Group rolesGroup = new Group(Group.ROLES);
+ GroupPrincipal rolesGroup = new GroupPrincipal(GroupPrincipal.ROLES);
rolesGroup.addMember(role);
getSubject().getPrincipals().add(rolesGroup);
} else {
- for (Group group : groups) {
- if (Group.ROLES.equals(group.getName())) {
+ for (GroupPrincipal group : groups) {
+ if (GroupPrincipal.ROLES.equals(group.getName())) {
group.addMember(role);
}
}
@@ -15,6 +15,7 @@
import java.io.Serializable;
import java.security.Principal;
+import java.security.acl.Group;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
@@ -23,14 +24,14 @@
import org.switchyard.security.BaseSecurityMessages;
/**
- * Group.
+ * GroupPrincipal.
*
* @author David Ward &lt;<a href="mailto:dward@jboss.org">dward@jboss.org</a>&gt; &copy; 2012 Red Hat Inc.
*/
-public class Group implements java.security.acl.Group, Serializable {
+public class GroupPrincipal implements Group, Serializable {
private static final long serialVersionUID = -909127780618924905L;
- private static final String FORMAT = Group.class.getSimpleName() + "@%s[name=%s, members=%s]";
+ private static final String FORMAT = GroupPrincipal.class.getSimpleName() + "@%s[name=%s, members=%s]";
/**
* The "Roles" group name.
@@ -41,10 +42,10 @@
private final Set<Principal> _members = new HashSet<Principal>();
/**
- * Constructs a Group with the specified name.
+ * Constructs a GroupPrincipal with the specified name.
* @param name the specified name
*/
- public Group(String name) {
+ public GroupPrincipal(String name) {
if (name == null) {
throw BaseSecurityMessages.MESSAGES.groupNameCannotBeNull();
}
@@ -125,7 +126,7 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass()) {
return false;
}
- Group other = (Group)obj;
+ GroupPrincipal other = (GroupPrincipal)obj;
if (_members == null) {
if (other._members != null) {
return false;
@@ -19,22 +19,22 @@
import org.switchyard.security.BaseSecurityMessages;
/**
- * Role.
+ * RolePrincipal.
*
* @author David Ward &lt;<a href="mailto:dward@jboss.org">dward@jboss.org</a>&gt; &copy; 2012 Red Hat Inc.
*/
-public class Role implements Principal, Serializable {
+public class RolePrincipal implements Principal, Serializable {
private static final long serialVersionUID = 7278196575770196005L;
- private static final String FORMAT = Role.class.getSimpleName() + "@%s[name=%s]";
+ private static final String FORMAT = RolePrincipal.class.getSimpleName() + "@%s[name=%s]";
private final String _name;
/**
- * Constructs a Role with the specified name.
+ * Constructs a RolePrincipal with the specified name.
* @param name the specified name
*/
- public Role(String name) {
+ public RolePrincipal(String name) {
if (name == null) {
throw BaseSecurityMessages.MESSAGES.roleCannotBeNull();
}
@@ -82,7 +82,7 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass()) {
return false;
}
- Role other = (Role)obj;
+ RolePrincipal other = (RolePrincipal)obj;
if (_name == null) {
if (other._name != null) {
return false;
@@ -19,22 +19,22 @@
import org.switchyard.security.BaseSecurityMessages;
/**
- * User.
+ * UserPrincipal.
*
* @author David Ward &lt;<a href="mailto:dward@jboss.org">dward@jboss.org</a>&gt; &copy; 2012 Red Hat Inc.
*/
-public class User implements Principal, Serializable {
+public class UserPrincipal implements Principal, Serializable {
private static final long serialVersionUID = 1931117417458834463L;
- private static final String FORMAT = User.class.getSimpleName() + "@%s[name=%s]";
+ private static final String FORMAT = UserPrincipal.class.getSimpleName() + "@%s[name=%s]";
private final String _name;
/**
- * Constructs a User with the specified name.
+ * Constructs a UserPrincipal with the specified name.
* @param name the specified name
*/
- public User(String name) {
+ public UserPrincipal(String name) {
if (name == null) {
throw BaseSecurityMessages.MESSAGES.userNameCannotBeNull();
}
@@ -82,7 +82,7 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass()) {
return false;
}
- User other = (User)obj;
+ UserPrincipal other = (UserPrincipal)obj;
if (_name == null) {
if (other._name != null) {
return false;
@@ -27,8 +27,8 @@
import org.switchyard.security.callback.handler.NamePasswordCallbackHandler;
import org.switchyard.security.callback.handler.SwitchYardCallbackHandler;
import org.switchyard.security.context.SecurityContext;
-import org.switchyard.security.principal.Group;
-import org.switchyard.security.principal.Role;
+import org.switchyard.security.principal.GroupPrincipal;
+import org.switchyard.security.principal.RolePrincipal;
/**
* JaasSecurityProvider.
@@ -87,18 +87,18 @@ public boolean addRunAs(ServiceSecurity serviceSecurity, SecurityContext securit
String runAs = Strings.trimToNull(serviceSecurity.getRunAs());
if (runAs != null) {
success = false;
- Role runAsRole = new Role(runAs);
+ RolePrincipal runAsRole = new RolePrincipal(runAs);
String securityDomain = serviceSecurity.getSecurityDomain();
Subject subject = securityContext.getSubject(securityDomain);
- Set<Group> groups = subject.getPrincipals(Group.class);
+ Set<GroupPrincipal> groups = subject.getPrincipals(GroupPrincipal.class);
if (groups.isEmpty()) {
- Group rolesGroup = new Group(Group.ROLES);
+ GroupPrincipal rolesGroup = new GroupPrincipal(GroupPrincipal.ROLES);
rolesGroup.addMember(runAsRole);
subject.getPrincipals().add(rolesGroup);
success = true;
} else {
- for (Group group : groups) {
- if (Group.ROLES.equals(group.getName())) {
+ for (GroupPrincipal group : groups) {
+ if (GroupPrincipal.ROLES.equals(group.getName())) {
group.addMember(runAsRole);
success = true;
}
@@ -37,9 +37,9 @@
import org.switchyard.security.credential.PrincipalCredential;
import org.switchyard.security.credential.extractor.SOAPMessageCredentialExtractorTests;
import org.switchyard.security.crypto.PrivateCrypto;
-import org.switchyard.security.principal.Group;
-import org.switchyard.security.principal.Role;
-import org.switchyard.security.principal.User;
+import org.switchyard.security.principal.GroupPrincipal;
+import org.switchyard.security.principal.RolePrincipal;
+import org.switchyard.security.principal.UserPrincipal;
/**
* SecurityContext tests.
@@ -81,17 +81,17 @@ public void testContextSealable() throws Exception {
private SecurityContext getContext() throws Exception {
SecurityContext context = new DefaultSecurityContext();
Subject subject = context.getSubject("testSecurityDomain");
- subject.getPrincipals().add(new User("testUser"));
+ subject.getPrincipals().add(new UserPrincipal("testUser"));
context.getCredentials().addAll(getCredentials());
return context;
}
private Set<Credential> getCredentials() throws Exception {
- User user = new User("testUser");
- Role role = new Role("testRole");
- Group parentGroup = new Group("testParentGroup");
+ UserPrincipal user = new UserPrincipal("testUser");
+ RolePrincipal role = new RolePrincipal("testRole");
+ GroupPrincipal parentGroup = new GroupPrincipal("testParentGroup");
parentGroup.addMember(user);
- Group childGroup = new Group("testChildGroup");
+ GroupPrincipal childGroup = new GroupPrincipal("testChildGroup");
childGroup.addMember(role);
parentGroup.addMember(childGroup);
Set<Credential> creds = new LinkedHashSet<Credential>();

0 comments on commit 230ca01

Please sign in to comment.