private boolean hasIdentityType(T token, StereotypeProperty.Property stereotypeProperty, Object identifier) { if (StereotypeProperty.Property.IDENTITY_ROLE_NAME.equals(stereotypeProperty)) { Set<String> roleNames = extractRoles(token); if (roleNames.contains(identifier)) { return true; } } if (StereotypeProperty.Property.IDENTITY_GROUP_NAME.equals(stereotypeProperty)) { Set<String> groupNames = extractGroups(token); if (groupNames.contains(identifier)) { return true; } } if (StereotypeProperty.Property.IDENTITY_USER_NAME.equals(stereotypeProperty) || StereotypeProperty.Property.IDENTITY_ID.equals(stereotypeProperty)) { String subject = extractSubject(token); if (subject != null && identifier.equals(subject)) { return true; } } return false; } }
private <I extends IdentityType> I extractIdentityTypeFromToken(T token, Class<I> identityType, StereotypeProperty.Property stereotypeProperty, Object identifier) { if (hasIdentityType(token, stereotypeProperty, identifier)) { try { I identityTypeInstance = Reflections.newInstance(identityType); Property property = resolveProperty(identityType, stereotypeProperty); property.setValue(identityTypeInstance, identifier); if (Account.class.isAssignableFrom(identityType)) { Property userNameProperty = resolveProperty(identityType, StereotypeProperty.Property.IDENTITY_USER_NAME); userNameProperty.setValue(identityTypeInstance, extractSubject(token)); } return identityTypeInstance; } catch (Exception e) { throw new IdentityManagementException("Could not extract IdentityType [" + identityType + "] from Token [" + token + "].", e); } } return null; }
@Override public <I extends IdentityType> I extractIdentity(T token, Class<I> identityType, StereotypeProperty.Property stereotypeProperty, Object identifier) { if (token == null || token.getToken() == null) { throw MESSAGES.nullArgument("Token"); } if (identityType == null) { throw MESSAGES.nullArgument("IdentityType"); } if (stereotypeProperty == null) { throw MESSAGES.nullArgument("Identifier value"); } if (identifier == null) { throw MESSAGES.nullArgument("Identifier value"); } return extractIdentityTypeFromToken(token, identityType, stereotypeProperty, identifier); }
@Override public <I extends IdentityType> I extractIdentity(T token, Class<I> identityType, StereotypeProperty.Property stereotypeProperty, Object identifier) { if (token == null || token.getToken() == null) { throw MESSAGES.nullArgument("Token"); } if (identityType == null) { throw MESSAGES.nullArgument("IdentityType"); } if (stereotypeProperty == null) { throw MESSAGES.nullArgument("Identifier value"); } if (identifier == null) { throw MESSAGES.nullArgument("Identifier value"); } return extractIdentityTypeFromToken(token, identityType, stereotypeProperty, identifier); }
private <I extends IdentityType> I extractIdentityTypeFromToken(T token, Class<I> identityType, StereotypeProperty.Property stereotypeProperty, Object identifier) { if (hasIdentityType(token, stereotypeProperty, identifier)) { try { I identityTypeInstance = Reflections.newInstance(identityType); Property property = resolveProperty(identityType, stereotypeProperty); property.setValue(identityTypeInstance, identifier); if (Account.class.isAssignableFrom(identityType)) { Property userNameProperty = resolveProperty(identityType, StereotypeProperty.Property.IDENTITY_USER_NAME); userNameProperty.setValue(identityTypeInstance, extractSubject(token)); } return identityTypeInstance; } catch (Exception e) { throw new IdentityManagementException("Could not extract IdentityType [" + identityType + "] from Token [" + token + "].", e); } } return null; }
private boolean hasIdentityType(T token, StereotypeProperty.Property stereotypeProperty, Object identifier) { if (StereotypeProperty.Property.IDENTITY_ROLE_NAME.equals(stereotypeProperty)) { Set<String> roleNames = extractRoles(token); if (roleNames.contains(identifier)) { return true; } } if (StereotypeProperty.Property.IDENTITY_GROUP_NAME.equals(stereotypeProperty)) { Set<String> groupNames = extractGroups(token); if (groupNames.contains(identifier)) { return true; } } if (StereotypeProperty.Property.IDENTITY_USER_NAME.equals(stereotypeProperty) || StereotypeProperty.Property.IDENTITY_ID.equals(stereotypeProperty)) { String subject = extractSubject(token); if (subject != null && identifier.equals(subject)) { return true; } } return false; } }