List of usage examples for java.security Principal getName
public String getName();
From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java
public static String acl2PolicyString(Acl acl) { Enumeration<AclEntry> entryEnum = acl.entries(); StringBuffer sb = new StringBuffer(); while (entryEnum.hasMoreElements()) { AclEntry entry = entryEnum.nextElement(); sb.append("grant principal "); Principal principal = entry.getPrincipal(); sb.append(principal.getClass().getName()).append(" \""); sb.append(principal.getName()).append("\" {\n\r"); Enumeration<Permission> permissEnum = entry.permissions(); while (permissEnum.hasMoreElements()) { Permission permission = permissEnum.nextElement(); sb.append("\t").append(PolicyUtil.permiss2PolicyString(permission)); }/*from w w w .j a v a 2 s . c o m*/ sb.append("};\n\r"); } return sb.toString(); }
From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java
public static Acl restoreReserved(Acl policy, Acl origin) { Enumeration<AclEntry> entryEnum = origin.entries(); ////ww w.j a v a 2 s . co m while (entryEnum.hasMoreElements()) { AclEntry entry = entryEnum.nextElement(); Principal principal = entry.getPrincipal(); String principalClass = principal.getClass().getName(); String principalName = principal.getName(); if (principalClass == null || principalName == null) continue; if (principalClass.equals("cn.vlabs.duckling.vwb.service.auth.Role") && principalName.equals("All")) { continue; } if (principalClass.equals("cn.vlabs.duckling.vwb.service.auth.GroupPrincipal")) { continue; } policy.addEntry(entry); } return policy; }
From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java
public static Acl removeReserved(Acl policy) { Enumeration<AclEntry> entryEnum = policy.entries(); // ?//from www. j a v a 2s. c om while (entryEnum.hasMoreElements()) { AclEntry entry = entryEnum.nextElement(); Principal principal = entry.getPrincipal(); String principalClass = principal.getClass().getName(); String principalName = principal.getName(); if (principalClass == null || principalName == null) continue; if (principalClass.equals("cn.vlabs.duckling.vwb.service.auth.Role") && principalName.equals("All")) { continue; } if (principalClass.equals("cn.vlabs.duckling.vwb.service.auth.GroupPrincipal")) { continue; } policy.removeEntry(entry); } return policy; }
From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java
public static Acl replacePolicy(Acl policy, String vogroup) { Enumeration<AclEntry> entryEnum = policy.entries(); while (entryEnum.hasMoreElements()) { AclEntry entry = entryEnum.nextElement(); Principal principal = entry.getPrincipal(); String principalClass = principal.getClass().getName(); String principalName = principal.getName(); if (principalClass == null || principalName == null) continue; if (principalClass.equals("cn.vlabs.duckling.vwb.service.auth.GroupPrincipal")) { Principal principalNew = new GroupPrincipal(vogroup); entry.setPrincipal(principalNew); }/* ww w . j av a 2s .co m*/ if (principalClass.equals("cn.vlabs.duckling.vwb.service.auth.Role")) { int pos = principalName.indexOf('.'); if (pos != -1) { String principalNameNew = vogroup + principalName.substring(pos, principalName.length()); Principal principalNew = new Role(principalNameNew); entry.setPrincipal(principalNew); } } } return policy; }
From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java
public static void remove(Acl policy, PolicyData pd) { Enumeration<AclEntry> entryEnum = policy.entries(); while (entryEnum.hasMoreElements()) { AclEntry entry = entryEnum.nextElement(); Principal principal = entry.getPrincipal(); String principalClass = principal.getClass().getName(); String principalName = principal.getName(); if (principalClass == null || principalName == null) continue; if (principalClass.equals(pd.getPrincipalClass()) && principalName.equals(pd.getPrincipalName())) { Enumeration<Permission> permissEnum = entry.permissions(); while (permissEnum.hasMoreElements()) { Permission permission = permissEnum.nextElement(); String permissionClass = permission.getClass().getName(); String permissionName = permission.getName(); String permissionActions = permission.getActions(); if (permissionClass == null || permissionName == null || permissionActions == null) continue; if (permissionClass.equals(pd.getPermissionClass()) && permissionName.equals(pd.getPermissionName()) && permissionActions.equals(pd.getPermissionActions())) { // AclEntry policyEntry = policy.getEntry(principal); policyEntry.removePermission(permission); }// ww w . j av a 2s.c o m } } } }
From source file:ddf.catalog.source.opensearch.OpenSearchSiteUtil.java
/** * Populates general site information.//from www . j a v a 2 s .c om * * @param client Initial StringBuilder url that is not filled in. * @param query * @param subject */ public static void populateSearchOptions(WebClient client, Query query, Subject subject, List<String> parameters) { String maxTotalSize = null; String maxPerPage = null; String routeTo = ""; String timeout = null; String start = "1"; String dn = null; String filterStr = ""; String sortStr = null; if (query != null) { maxPerPage = String.valueOf(query.getPageSize()); if (query.getPageSize() > DEFAULT_TOTAL_MAX) { maxTotalSize = maxPerPage; } else if (query.getPageSize() <= 0) { maxTotalSize = String.valueOf(DEFAULT_TOTAL_MAX); } start = Integer.toString(query.getStartIndex()); timeout = Long.toString(query.getTimeoutMillis()); sortStr = translateToOpenSearchSort(query.getSortBy()); if (subject != null && subject.getPrincipals() != null && !subject.getPrincipals().isEmpty()) { List principals = subject.getPrincipals().asList(); for (Object principal : principals) { if (principal instanceof SecurityAssertion) { SecurityAssertion assertion = (SecurityAssertion) principal; Principal assertionPrincipal = assertion.getPrincipal(); if (assertionPrincipal != null) { dn = assertionPrincipal.getName(); } } } } } checkAndReplace(client, start, START_INDEX, parameters); checkAndReplace(client, maxPerPage, COUNT, parameters); checkAndReplace(client, maxTotalSize, MAX_RESULTS, parameters); checkAndReplace(client, routeTo, SRC, parameters); checkAndReplace(client, timeout, MAX_TIMEOUT, parameters); checkAndReplace(client, dn, USER_DN, parameters); checkAndReplace(client, filterStr, FILTER, parameters); checkAndReplace(client, sortStr, SORT, parameters); }
From source file:ips1ap101.lib.core.control.UsuarioAutenticado.java
static String getPrincipalName() { Principal principal = JSF.getPrincipal(); return principal == null ? CODIGO_USUARIO_DESCONOCIDO : principal.getName(); }
From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java
public static List<PolicyData> acl2PolicyData(Acl acl) { List<PolicyData> pdl = new ArrayList<PolicyData>(); Enumeration<AclEntry> entryEnum = acl.entries(); while (entryEnum.hasMoreElements()) { AclEntry entry = entryEnum.nextElement(); Principal principal = entry.getPrincipal(); String principalClass = principal.getClass().getName(); String principalName = principal.getName(); String objectname = null; if (principalClass.equals("cn.vlabs.duckling.vwb.service.auth.Role") && principalName.equalsIgnoreCase("All")) { objectname = ""; }//from w ww . j a v a2 s.c om if (principalClass.equals("cn.vlabs.duckling.vwb.service.auth.GroupPrincipal")) { objectname = ""; } if (objectname == null) { continue; } Enumeration<Permission> permissEnum = entry.permissions(); while (permissEnum.hasMoreElements()) { Permission permission = permissEnum.nextElement(); String permissionClass = permission.getClass().getName(); String permissionType = null; if (permissionClass.equals("cn.vlabs.duckling.vwb.service.auth.permissions.PagePermission")) { permissionType = "?"; } if (permissionClass.equals("cn.vlabs.duckling.vwb.service.auth.permissions.VWBPermission")) { permissionType = ""; } if (permissionType == null) { continue; } String permissionActions = permission.getActions(); String operations = permissionActions; String permissionName = permission.getName(); String resource = null; if (permission instanceof UserPermission) { resource = ((UserPermission) permission).getWiki(); } else if (permission instanceof VWBPermission) { resource = "*"; } else if (permission instanceof PagePermission) { resource = ((PagePermission) permission).getPage(); } else if (permission instanceof AllPermission) { resource = "*"; } else { resource = permission.getName(); } PolicyData pd = new PolicyData(); pd.setId(pdl.size()); pd.setPrincipalClass(principalClass); pd.setPrincipalName(principalName); pd.setPermissionClass(permissionClass); pd.setPermissionActions(permissionActions); pd.setPermissionName(permissionName); pd.setPrincipal(objectname); pd.setPermission(permissionType); pd.setOperation(operations); pd.setResource(resource); pdl.add(pd); } } return pdl; }
From source file:com.google.gsa.valve.modules.krb.KerberosAuthenticationProcess.java
/** * Gets the main principal from the user subject got as a result * of the Kerberos authentication process * /* w ww . ja v a2s.com*/ * @param subject user subject * * @return the user principal */ public static String getPrincipalStr(Subject subject) { String principal = null; logger.debug("Getting principal from Subject"); try { Set principals = subject.getPrincipals(); if (!principals.isEmpty()) { logger.debug("Subject contains at least one Principal"); Iterator it = principals.iterator(); if (it.hasNext()) { Principal ppal = (Principal) it.next(); principal = ppal.getName().substring(0, ppal.getName().indexOf("@")); logger.debug("Getting the first principal: " + principal); } } } catch (Exception e) { logger.error("Error retrieving the client's Principal from the Subject: " + e.getMessage(), e); } return principal; }
From source file:com.dtolabs.rundeck.core.authorization.RuleEvaluator.java
static Decision createAuthorize(final boolean authorized, final Explanation explanation, final Map<String, String> resource, final Subject subject, final String action, final Set<Attribute> environment, final long evaluationTime) { return new Decision() { private String representation; public boolean isAuthorized() { return authorized; }// www. j av a 2 s .c o m public Map<String, String> getResource() { return resource; } public String getAction() { return action; } public Set<Attribute> getEnvironment() { return environment; } public Subject getSubject() { return subject; } public String toString() { if (representation == null) { StringBuilder builder = new StringBuilder(); builder.append("Decision for: "); builder.append("res<"); Iterator<Map.Entry<String, String>> riter = resource.entrySet().iterator(); while (riter.hasNext()) { Map.Entry<String, String> s = riter.next(); builder.append(s.getKey()).append(':').append(s.getValue()); if (riter.hasNext()) { builder.append(", "); } } builder.append("> subject<"); Iterator<Principal> iter = subject.getPrincipals().iterator(); while (iter.hasNext()) { Principal principal = iter.next(); builder.append(principal.getClass().getSimpleName()); builder.append(':'); builder.append(principal.getName()); if (iter.hasNext()) { builder.append(' '); } } builder.append("> action<"); builder.append(action); builder.append("> env<"); Iterator<Attribute> eiter = environment.iterator(); while (eiter.hasNext()) { Attribute a = eiter.next(); builder.append(a); if (eiter.hasNext()) { builder.append(", "); } } builder.append(">"); builder.append(": authorized: "); builder.append(isAuthorized()); builder.append(": "); builder.append(explanation.toString()); this.representation = builder.toString(); } return this.representation; } public Explanation explain() { return explanation; } public long evaluationDuration() { return evaluationTime; } }; }