Преглед изворни кода

v3.0.0GA with SAML User Attributes

Crystal.Sea пре 3 година
родитељ
комит
41df3c5c46

+ 7 - 0
maxkey-core/src/main/java/org/maxkey/constants/ldap/ActiveDirectoryUser.java

@@ -178,6 +178,13 @@ public class ActiveDirectoryUser {
 	public static final String UNICODEPWD 					= "unicodePwd";
 	public static final String DISTINGUISHEDNAME 			= "distinguishedname";
 	
+	//MaxKey EXTEND
+	public static final String MANAGERNAME                  = "managerName";
+	public static final String USERNAME                     = "username";
+	public static final String USERTYPE                     = "userType";
+	public static final String GENDER                       = "gender";
+	public static final String USERSTATUS                   = "status";
+	
 	
 	public static byte[] encodePassword(String password) throws UnsupportedEncodingException {
 	        return ("\"" + password + "\"").getBytes("UTF-16LE");

+ 4 - 2
maxkey-protocols/maxkey-protocol-saml-2.0/src/main/java/org/maxkey/authz/saml20/provider/endpoint/AssertionEndpoint.java

@@ -72,9 +72,9 @@ public class AssertionEndpoint {
 		}
 
 		logger.debug("AuthnRequestInfo: {}", authnRequestInfo);
-
 		HashMap <String,String>attributeMap=new HashMap<String,String>();
-		attributeMap.put(WebConstants.ONLINE_TICKET_NAME, ((SigninPrincipal)WebContext.getAuthentication().getPrincipal()).getOnlineTicket().getTicketId());
+		attributeMap.put(WebConstants.ONLINE_TICKET_NAME, 
+		        ((SigninPrincipal)WebContext.getAuthentication().getPrincipal()).getOnlineTicket().getTicketId());
 		
 		//saml20Details
 		Response authResponse = authnResponseGenerator.generateAuthnResponse(
@@ -97,5 +97,7 @@ public class AssertionEndpoint {
 		}
 		return null;
 	}
+	
+	
 
 }

+ 29 - 1
maxkey-protocols/maxkey-protocol-saml-2.0/src/main/java/org/maxkey/authz/saml20/provider/xml/AttributeStatementGenerator.java

@@ -25,9 +25,12 @@ import java.util.Map;
 import java.util.Map.Entry;
 
 import org.maxkey.constants.Boolean;
+import org.maxkey.constants.ldap.ActiveDirectoryUser;
 import org.maxkey.entity.ExtraAttr;
 import org.maxkey.entity.ExtraAttrs;
+import org.maxkey.entity.UserInfo;
 import org.maxkey.entity.apps.AppsSAML20Details;
+import org.maxkey.web.WebContext;
 import org.opensaml.Configuration;
 import org.opensaml.saml2.core.Attribute;
 import org.opensaml.saml2.core.AttributeStatement;
@@ -62,6 +65,8 @@ public class AttributeStatementGenerator {
 		Attribute attributeGrantedAuthority=builderGrantedAuthority(grantedAuthoritys);
 		attributeStatement.getAttributes().add(attributeGrantedAuthority);
 		
+		putUserAttributes(attributeMap);
+		
 		if(null!=attributeMap){
 			Iterator<Entry<String, String>> iterator = attributeMap.entrySet().iterator();
 			while (iterator.hasNext()) {
@@ -121,6 +126,29 @@ public class AttributeStatementGenerator {
 		return xsStringValue;
 	}
 	
-	
+	public HashMap <String,String> putUserAttributes(HashMap <String,String> attributeMap){
+        UserInfo userInfo = WebContext.getUserInfo();
+        attributeMap.put(ActiveDirectoryUser.USERNAME, userInfo.getUsername());
+        attributeMap.put(ActiveDirectoryUser.UID, userInfo.getUsername());
+        
+        attributeMap.put(ActiveDirectoryUser.EMPLOYEENUMBER, userInfo.getEmployeeNumber());
+        attributeMap.put(ActiveDirectoryUser.DEPARTMENTNUMBER, userInfo.getDepartmentId());
+        attributeMap.put(ActiveDirectoryUser.DEPARTMENT, userInfo.getDepartment());
+        attributeMap.put(ActiveDirectoryUser.COMPANY, userInfo.getDivision());
+        attributeMap.put(ActiveDirectoryUser.TITLE, userInfo.getJobTitle());
+        attributeMap.put(ActiveDirectoryUser.MANAGER, userInfo.getManagerId());
+        attributeMap.put(ActiveDirectoryUser.MANAGERNAME, userInfo.getManager());
+        
+        attributeMap.put(ActiveDirectoryUser.DISPLAYNAME, userInfo.getDisplayName());
+        attributeMap.put(ActiveDirectoryUser.GIVENNAME, userInfo.getGivenName());
+        attributeMap.put(ActiveDirectoryUser.SN, userInfo.getFamilyName());
+        attributeMap.put(ActiveDirectoryUser.GENDER, userInfo.getGender() + "");
+        attributeMap.put(ActiveDirectoryUser.MAIL, userInfo.getEmail());
+        attributeMap.put(ActiveDirectoryUser.MOBILE, userInfo.getMobile());
+        
+        attributeMap.put(ActiveDirectoryUser.USERSTATUS, userInfo.getStatus() + "");
+        
+        return attributeMap;
+    }
 
 }

+ 1 - 1
maxkey-webs/maxkey-web-resources/build.gradle

@@ -1,4 +1,4 @@
-description = "maxkey-web-static"
+description = "maxkey-web-resources"
 
 //add support for Java
 apply plugin: 'java'