当前位置: 首页>>代码示例>>Java>>正文


Java SAMLCredential类代码示例

本文整理汇总了Java中org.springframework.security.saml.SAMLCredential的典型用法代码示例。如果您正苦于以下问题:Java SAMLCredential类的具体用法?Java SAMLCredential怎么用?Java SAMLCredential使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SAMLCredential类属于org.springframework.security.saml包,在下文中一共展示了SAMLCredential类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAttributes

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
@Test
public void testAttributes() {
    SAMLCredential samlCredential = mock(SAMLCredential.class);
    NameID nameId = mock(NameID.class);
    when(samlCredential.getNameID()).thenReturn(nameId);
    Attribute attribute = mock(Attribute.class);
    when(attribute.getName()).thenReturn("attr");
    when(samlCredential.getAttributes()).thenReturn(Collections.singletonList(attribute));
    when(samlCredential.getAttribute("attr")).thenReturn(attribute);
    when(samlCredential.getAttributeAsString("attr")).thenReturn("value");
    when(samlCredential.getAttributeAsStringArray("attr")).thenReturn(new String[]{"value"});
    when(nameId.toString()).thenReturn(NameID.UNSPECIFIED);
    SAMLUserDetails details = (SAMLUserDetails) new SimpleSAMLUserDetailsService().loadUserBySAML(samlCredential);
    assertThat(details.getPassword()).isEmpty();
    assertThat(details.isAccountNonExpired()).isTrue();
    assertThat(details.isAccountNonLocked()).isTrue();
    assertThat(details.isCredentialsNonExpired()).isTrue();
    assertThat(details.isEnabled()).isTrue();
    assertThat(details.getAuthorities()).extracting(GrantedAuthority::getAuthority).containsExactly("ROLE_USER");
    assertThat(details.getAttribute("attr")).isEqualTo("value");
    assertThat(details.getAttributeArray("attr")).containsExactly("value");
    assertThat(details.getAttributes()).containsOnlyKeys("attr").containsValue("value");
    assertThat(details.getAttributesArrays()).containsOnlyKeys("attr");
    assertThat(details.getAttributesArrays().get("attr")).containsExactly("value");
}
 
开发者ID:ulisesbocchio,项目名称:spring-boot-security-saml,代码行数:26,代码来源:SimpleSAMLUserDetailsServiceTest.java

示例2: testAttributes

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
@Test
public void testAttributes() {
    SAMLCredential samlCredential = mock(SAMLCredential.class);
    NameID nameId = mock(NameID.class);
    when(samlCredential.getNameID()).thenReturn(nameId);
    Attribute attribute = mock(Attribute.class);
    when(attribute.getName()).thenReturn("attr");
    when(samlCredential.getAttributes()).thenReturn(Collections.singletonList(attribute));
    when(samlCredential.getAttribute("attr")).thenReturn(attribute);
    when(samlCredential.getAttributeAsString("attr")).thenReturn("value");
    when(samlCredential.getAttributeAsStringArray("attr")).thenReturn(new String[]{"value"});
    when(nameId.toString()).thenReturn(NameID.UNSPECIFIED);
    SAMLUserDetails details = new SAMLUserDetails(samlCredential);
    assertThat(details.getPassword()).isEmpty();
    assertThat(details.isAccountNonExpired()).isTrue();
    assertThat(details.isAccountNonLocked()).isTrue();
    assertThat(details.isCredentialsNonExpired()).isTrue();
    assertThat(details.isEnabled()).isTrue();
    assertThat(details.getAuthorities()).extracting(GrantedAuthority::getAuthority).containsExactly("ROLE_USER");
    assertThat(details.getAttribute("attr")).isEqualTo("value");
    assertThat(details.getAttributeArray("attr")).containsExactly("value");
    assertThat(details.getAttributes()).containsOnlyKeys("attr").containsValue("value");
    assertThat(details.getAttributesArrays()).containsOnlyKeys("attr");
    assertThat(details.getAttributesArrays().get("attr")).containsExactly("value");
}
 
开发者ID:ulisesbocchio,项目名称:spring-boot-security-saml,代码行数:26,代码来源:SAMLUserDetailsTest.java

示例3: userDetailsService

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
@Bean
public SAMLUserDetailsService userDetailsService() {
    return new SAMLUserDetailsService() {
        @Override
        public Object loadUserBySAML(SAMLCredential samlCredential) throws UsernameNotFoundException {
            return new SAMLUserDetails(samlCredential) {
                @Override
                public Map<String, String> getAttributes() {
                    return samlCredential.getAttributes().stream()
                            .collect(Collectors.toMap(Attribute::getName, this::getValue));
                }

                private String getValue(Attribute attribute) {
                    return Optional.ofNullable(getAttribute(attribute.getName())).orElse("");
                }
            };
        }
    };
}
 
开发者ID:ulisesbocchio,项目名称:spring-boot-security-saml-samples,代码行数:20,代码来源:Auth0SSODemoApplication.java

示例4: getUserId

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
private static String getUserId( SAMLCredential credential )
{
    String userId = null;
    for ( org.opensaml.saml2.core.Attribute attr : credential.getAttributes())
    {
        String fname = attr.getFriendlyName();
        if(StringUtils.isEmpty( fname ) )
        {
            break;
        }
        else if( fname.equals( "uid" ) )
        {
            String vals[] = credential.getAttributeAsStringArray( attr.getName() );
            userId = vals[0];
            break;
        }
    }
    return userId;
}
 
开发者ID:shawnmckinney,项目名称:fortress-saml-demo,代码行数:20,代码来源:SecUtils.java

示例5: getSurName

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
private static String getSurName( SAMLCredential credential )
{
    String userId = null;
    for ( org.opensaml.saml2.core.Attribute attr : credential.getAttributes())
    {
        String name = attr.getName();
        if(StringUtils.isEmpty( name ) )
        {
            break;
        }
        else if( name.equals( "LastName" ) )
        {
            String vals[] = credential.getAttributeAsStringArray( attr.getName() );
            userId = vals[0];
            break;
        }
    }
    return userId;
}
 
开发者ID:shawnmckinney,项目名称:fortress-saml-demo,代码行数:20,代码来源:SecUtils.java

示例6: getGrantedAuthorities

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
private List<GrantedAuthority> getGrantedAuthorities(SAMLCredential credential) {
    String rolesClaim = credential.getAttributeAsString("http://wso2.org/claims/role");
    List<GrantedAuthority> authorities = new ArrayList<>();
    if (StringUtils.isNotBlank(rolesClaim)) {
        String[] splitRolesClaim = StringUtils.split(rolesClaim, ",");
        for (String roleClaim : splitRolesClaim) {
            RoleId roleId = RoleId.valueById(roleClaim);
            if (roleId != null) {
                authorities.add(new SimpleGrantedAuthority(roleId.getId()));
            }
        }
    }

    // fallback in case the IdP did not provide any role claims
    if (authorities.isEmpty()) {
        authorities.add(new SimpleGrantedAuthority(RoleId.USER_ROLE_ID.getId()));
    }

    return Collections.unmodifiableList(authorities);
}
 
开发者ID:chrludwig,项目名称:websec-saml2sp,代码行数:21,代码来源:SAMLUserDetailsServiceImpl.java

示例7: loadUserBySAML

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
public Object loadUserBySAML(SAMLCredential credential)
		throws UsernameNotFoundException {
	
	// The method is supposed to identify local account of user referenced by
	// data in the SAML assertion and return UserDetails object describing the user.
	
	String userID = credential.getNameID().getValue();
	
	LOG.info(userID + " is logged in");
	List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
	GrantedAuthority authority = new SimpleGrantedAuthority("ROLE_USER");
	authorities.add(authority);

	// In a real scenario, this implementation has to locate user in a arbitrary
	// dataStore based on information present in the SAMLCredential and
	// returns such a date in a form of application specific UserDetails object.
	return new User(userID, "<abc123>", true, true, true, true, authorities);
}
 
开发者ID:vdenotaris,项目名称:spring-boot-security-saml-sample,代码行数:19,代码来源:SAMLUserDetailsServiceImpl.java

示例8: loadUserBySAML

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
public Object loadUserBySAML(SAMLCredential credential)
        throws UsernameNotFoundException {
    XSAnyImpl uid =
            (XSAnyImpl) credential.getAttributes().stream()
                    .filter(a -> a.getFriendlyName().equals("uid"))
                    .findFirst().
                            orElseThrow(() -> new UsernameNotFoundException("uid not found from assertion"))
                    .getAttributeValues().get(0);

    List<GrantedAuthority> authorities = new ArrayList<>();
    return new User(uid.getTextContent(), "", true, true, true, true, authorities);
}
 
开发者ID:lhartikk,项目名称:spring-tsers-auth,代码行数:13,代码来源:SAMLUserDetailsServiceImpl.java

示例9: loadUserBySAML

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
@Override
public Object loadUserBySAML(SAMLCredential credential) throws UsernameNotFoundException {
	logger.info("LOADING USER BASED ON SAML AUTHENTICATION OBJECT......{}", credential.toString());
	User u = new User();
	u.setUsername(credential.getAttributeAsString("EmailAddress"));
	u.setFirstName(credential.getAttributeAsString("FirstName"));
	u.setLastName(credential.getAttributeAsString("LastName"));
	
	//TODO You can do lookup in db based on some unique identified came from SAML Response and then prepare the user object with its
	//granted authorities so that later on it can be used either by spring security or you to grant certain access to part of your app
	logger.info(u.toString());
	return u;
}
 
开发者ID:pritspatel,项目名称:spring-saml-angular2,代码行数:14,代码来源:UserDetailService.java

示例10: loadUserBySAML

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
@Override
public Object loadUserBySAML(SAMLCredential credential)
                throws UsernameNotFoundException {

    String userID = credential.getNameID().getValue();

    LOG.info(userID + " is logged in");
    List<GrantedAuthority> authorities = new ArrayList<>();
    GrantedAuthority authority = new SimpleGrantedAuthority("ROLE_USER");
    authorities.add(authority);

    return new User(userID, "<abc123>", true, true, true, true, authorities);
}
 
开发者ID:takesection,项目名称:spring-boot-saml2,代码行数:14,代码来源:SAMLUserDetailsServiceImpl.java

示例11: stubSAMLCredential

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
private SAMLCredential stubSAMLCredential() {
	return new SAMLCredential(
			mock(NameID.class),
			mock(Assertion.class),
			"entity",
			"local");
}
 
开发者ID:spring-projects,项目名称:spring-security-saml-dsl,代码行数:8,代码来源:SAMLConfigurerProfileConsumerTests.java

示例12: loadUserBySAML

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
@Override
public Object loadUserBySAML(SAMLCredential credential) throws UsernameNotFoundException {
    com.sungardas.enhancedsnapshots.aws.dynamodb.model.User user = userService.getUser(credential.getNameID().getValue().toLowerCase());
    if (user == null) {
        String email = credential.getNameID().getValue().toLowerCase();
        UserDto userDto = new UserDto();
        userDto.setEmail(email);
        userDto.setRole(Roles.USER.getName());
        userService.createUser(userDto, "");
        user = userService.getUser(email);
    }
    return new User(credential.getNameID().getValue(), "",
            Arrays.asList(new SimpleGrantedAuthority(ROLE_PREFIX + user.getRole().toUpperCase())));
}
 
开发者ID:SungardAS,项目名称:enhanced-snapshots,代码行数:15,代码来源:SamlUserDetails.java

示例13: authenticate

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    if (configurationMediator.isSungardasSSO()) {
        Authentication result = super.authenticate(authentication);

        SAMLCredential credential = (SAMLCredential) result.getCredentials();
        Attribute attribute = credential.getAttribute(ALLOWED_LIST_ATTRIBUTE_NAME);
        if (attribute != null) {
            for (XMLObject object : attribute.getAttributeValues()) {
                String value = ((XSStringImpl) object).getValue();
                if (ADMIN_WILDCARD_EXP.equals(value)) {
                    LOG.warn("User ({}) has admin access, instance UUID: {}", credential.getNameID().getValue(), configurationMediator.getUUID());
                    return result;
                }
                if (configurationMediator.getUUID().equals(value)) {
                    return result;
                }
            }
        }

        LOG.error("User ({}) has not allowed to use this instance with UUID: {}", credential.getNameID().getValue(), configurationMediator.getUUID());

        userService.removeUser(result.getName());

        throw new AuthenticationServiceException("Access denied");
    } else {
        return super.authenticate(authentication);
    }
}
 
开发者ID:SungardAS,项目名称:enhanced-snapshots,代码行数:30,代码来源:SAMLAuthenticationProviderImpl.java

示例14: loadUserBySAML

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
@Override
public Object loadUserBySAML( SAMLCredential credential ) throws UsernameNotFoundException {

  if ( getUserDetailsService() instanceof SAMLUserDetailsService ) {
    // inner UserDetailsService is also an implementation of SAMLUserDetailsService ? Great!
    // In that case we can also delegate any incoming loadUserBySAML() calls
    Object userDetails = ( (SAMLUserDetailsService) getUserDetailsService() ).loadUserBySAML( credential );
    if ( userDetails == null ) {
      logger.warn(
          "Got a null from calling the method loadUserBySAML( SAMLCredential credential ) of UserDetailsService: "
              + getUserDetailsService()
              + ". This is an interface violation beacuse it is specified that loadUserByUsername method should never return null. Throwing a UsernameNotFoundException." );
      throw new UsernameNotFoundException( credential.getRemoteEntityID() );
    }

    return ( (SAMLUserDetailsService) getUserDetailsService() ).loadUserBySAML( credential );
  }

  // default UserDetail build, using as reference the passed SAMLCredential

  if ( credential == null || credential.getNameID() == null || credential.getNameID().getValue() == null ) {
    throw new UsernameNotFoundException( "invalid/null SAMLCredential" );
  }

  String username = credential.getNameID().getValue();

  return loadUserByUsername( username );
}
 
开发者ID:pentaho,项目名称:pentaho-engineering-samples,代码行数:29,代码来源:PentahoSamlUserDetailsService.java

示例15: loadUserBySAML

import org.springframework.security.saml.SAMLCredential; //导入依赖的package包/类
@Override
public Object loadUserBySAML(SAMLCredential credential)
		throws UsernameNotFoundException {
	String usersId = credential.getAttributeAsString("USERS_ID");
	String displayName = credential.getAttributeAsString("DISPLAY_NAME");
	String loginName = credential.getAttributeAsString("LOGIN_NAME");
	String[] groupIds = credential.getAttributeAsStringArray("GROUP_IDS");
	String[] groupNames = credential.getAttributeAsStringArray("GROUPS");
	//String activeFlag = credential.getAttributeAsString("ACTIVE_FLAG");
	String primaryIpAddress =  credential.getAttributeAsString("PRIMARY_IP_ADDRESS");
	String primaryMemberGroupId =  credential.getAttributeAsString("PRIMARY_MEMBER_GROUP_ID");

       Users user = new Users();
       IpAddress ip = new IpAddress();
       ip.setIpAddress(primaryIpAddress);
       
       user.setUsersId(Integer.parseInt(usersId));
       user.setDisplayName(displayName);
       user.setLoginName(displayName);
       user.setFromDb(false);
       //user.setActiveFlag(activeFlag != null && activeFlag.equals("1") ? true : false);
       user.setPrimaryIpAddress(ip);
       user.setPrimaryMemberGroupId(Integer.parseInt(primaryMemberGroupId));
       
       Map<Integer, String> groups = new HashMap<Integer, String>();
       
       for(int i = 0; i < groupIds.length; i++){
       	groups.put(Integer.parseInt(groupIds[i]), groupNames[i]);
       }
       
       user.setMemberGroups(groups);
       
       return user;
}
 
开发者ID:ZFGCCP,项目名称:ZFGC3,代码行数:35,代码来源:SamlUsersDetailsServiceImpl.java


注:本文中的org.springframework.security.saml.SAMLCredential类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。