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


Java GenericPrincipal类代码示例

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


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

示例1: setAnonymousRoles

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
private void setAnonymousRoles(final Request request) {
    final List<String> roles = new ArrayList<String>();
    roles.add("anonymous");
    roles.add("islandora");
    final String name = "anonymous";
    final GenericPrincipal principal = new GenericPrincipal(name, null, roles);
    request.setUserPrincipal(principal);
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:9,代码来源:SynValve.java

示例2: setUserRolesFromStaticToken

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
private void setUserRolesFromStaticToken(final Request request, final Token token) {
    final List<String> roles = token.getRoles();
    roles.add("islandora");
    final String name = token.getUser();
    final GenericPrincipal principal = new GenericPrincipal(name, null, roles);
    request.setUserPrincipal(principal);
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:8,代码来源:SynValve.java

示例3: setUserRolesFromToken

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
private void setUserRolesFromToken(final Request request, final Verifier verifier) {
    final List<String> roles = verifier.getRoles();
    roles.add("islandora");
    roles.add(verifier.getUrl());
    final String name = verifier.getName();
    final GenericPrincipal principal = new GenericPrincipal(name, null, roles);
    request.setUserPrincipal(principal);
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:9,代码来源:SynValve.java

示例4: shouldPassAuthToken

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
@Test
public void shouldPassAuthToken() throws Exception {
    final ArgumentCaptor<GenericPrincipal> argument = ArgumentCaptor.forClass(GenericPrincipal.class);
    final String token = "Bearer 1337";
    final SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setAuthConstraint(true);
    when(realm.findSecurityConstraints(request, request.getContext()))
            .thenReturn(new SecurityConstraint[] { securityConstraint });
    when(request.getHeader("Authorization"))
            .thenReturn(token);

    synValve.start();
    synValve.invoke(request, response);

    final InOrder inOrder = inOrder(request, nextValve);
    inOrder.verify(request).getHeader("Authorization");
    inOrder.verify(request).setUserPrincipal(argument.capture());
    inOrder.verify(request).setAuthType("SYN");
    inOrder.verify(nextValve).invoke(request, response);

    assertEquals("islandoraAdmin", argument.getValue().getName());
    final List<String> roles = Arrays.asList(argument.getValue().getRoles());
    assertEquals(1, roles.size());
    assertTrue(roles.contains("islandora"));
    assertNull(argument.getValue().getPassword());
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:27,代码来源:SynValveTest.java

示例5: addUser

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
/**
 * Add a new user to the map
 *
 * @param username User's username
 * @param password User's password (clear text)
 * @param roles    Comma-delimited set of roles associated with
 *                 this user
 */
private void addUser(final String username, final String password, final String roles) {
  // Accumulate the list of roles for this user
  String rolesToProcess = roles + ',';
  final ArrayList list = new ArrayList(1);
  while (true) {
    final int comma = rolesToProcess.indexOf(',');
    if (comma < 0) break;
    final String role = rolesToProcess.substring(0, comma).trim();
    list.add(role);
    rolesToProcess = rolesToProcess.substring(comma + 1);
  }

  // Construct and cache the Principal for this user
  final GenericPrincipal principal = new GenericPrincipal(this, username, password, list);
  principals.put(username, principal);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:25,代码来源:Realm.java

示例6: writePrincipal

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
public static void writePrincipal(GenericPrincipal p, ObjectOutput out) throws IOException {
	out.writeUTF(p.getName());
	out.writeBoolean(p.getPassword() != null);
	if (p.getPassword() != null)
		out.writeUTF(p.getPassword());
	String[] roles = p.getRoles();
	if (roles == null)
		roles = new String[0];
	out.writeInt(roles.length);
	for (int i = 0; i < roles.length; i++)
		out.writeUTF(roles[i]);
	boolean hasUserPrincipal = (p != p.getUserPrincipal() && p.getUserPrincipal() instanceof Serializable);
	out.writeBoolean(hasUserPrincipal);
	if (hasUserPrincipal)
		out.writeObject(p.getUserPrincipal());
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:17,代码来源:SerializablePrincipal.java

示例7: logout

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
@Override
public void logout(Request request) throws ServletException {
	Principal p = request.getPrincipal();
	if (p instanceof GenericPrincipal) {
		try {
			((GenericPrincipal) p).logout();
		} catch (Throwable t) {
			ExceptionUtils.handleThrowable(t);
			log.debug(sm.getString("authenticator.tomcatPrincipalLogoutFail"), t);
		}
	}

	register(request, request.getResponse(), null, null, null, null);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:15,代码来源:AuthenticatorBase.java

示例8: readPrincipal

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
public static GenericPrincipal readPrincipal(ObjectInput in)
        throws IOException, ClassNotFoundException {
    String name = in.readUTF();
    boolean hasPwd = in.readBoolean();
    String pwd = null;
    if ( hasPwd ) pwd = in.readUTF();
    int size = in.readInt();
    String[] roles = new String[size];
    for ( int i=0; i<size; i++ ) roles[i] = in.readUTF();
    Principal userPrincipal = null;
    boolean hasUserPrincipal = in.readBoolean();
    if (hasUserPrincipal) {
        try {
            userPrincipal = (Principal) in.readObject();
        } catch (ClassNotFoundException e) {
            log.error(sm.getString(
                    "serializablePrincipal.readPrincipal.cnfe"), e);
            throw e;
        }
    }
    return new GenericPrincipal(name,pwd,Arrays.asList(roles),
            userPrincipal);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:SerializablePrincipal.java

示例9: isCallerInRole

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
@Override
public boolean isCallerInRole(final String role) {
    final Principal principal = getCallerPrincipal();
    if (TomcatUser.class.isInstance(principal)) {
        if ("**".equals(role)) {
            return true; // ie logged in through tomcat
        }

        final TomcatUser tomcatUser = (TomcatUser) principal;
        final GenericPrincipal genericPrincipal = (GenericPrincipal) tomcatUser.getTomcatPrincipal();
        final String[] roles = genericPrincipal.getRoles();
        if (roles != null) {
            for (final String userRole : roles) {
                if (userRole.equals(role)) {
                    return true;
                }
            }
        }
        return false;
    }
    return super.isCallerInRole(role);
}
 
开发者ID:apache,项目名称:tomee,代码行数:23,代码来源:TomcatSecurityService.java

示例10: authenticate

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
/**
 * Return the Principal associated with the specified username and
 * credentials, if one exists in the user data store; otherwise return null.
 */
@Override
public Principal authenticate(String username, String credentials) {
    GenericPrincipal principal = (GenericPrincipal) getPrincipal(username);
    if (null != principal) {
        try {
            if (!PasswordStorage.verifyPassword(credentials, principal.getPassword())) {
                principal = null;
            }
        } catch (CannotPerformOperationException | InvalidHashException e) {
            LOGR.log(Level.WARNING, e.getMessage());
            principal = null;
        }
    }
    return principal;
}
 
开发者ID:opengeospatial,项目名称:teamengine,代码行数:20,代码来源:PBKDF2Realm.java

示例11: shouldPassAuthDefaultSite

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
@Test
public void shouldPassAuthDefaultSite() throws Exception {
    final String host = "http://test2.com";
    final String token = JWT
            .create()
            .withClaim("uid", 1)
            .withClaim("name", "normalUser")
            .withClaim("url", host)
            .withArrayClaim("roles", new String[] {})
            .withIssuedAt(Date.from(LocalDateTime.now().toInstant(offset)))
            .withExpiresAt(Date.from(LocalDateTime.now().plusHours(2).toInstant(offset)))
            .sign(Algorithm.HMAC256("secret2"));

    final ArgumentCaptor<GenericPrincipal> argument = ArgumentCaptor.forClass(GenericPrincipal.class);

    final SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setAuthConstraint(true);
    when(realm.findSecurityConstraints(request, request.getContext()))
            .thenReturn(new SecurityConstraint[] { securityConstraint });
    when(request.getHeader("Authorization"))
            .thenReturn("Bearer " + token);

    synValve.start();
    synValve.invoke(request, response);

    final InOrder inOrder = inOrder(request, nextValve);
    inOrder.verify(request).getHeader("Authorization");
    inOrder.verify(request).setUserPrincipal(argument.capture());
    inOrder.verify(request).setAuthType("SYN");
    inOrder.verify(nextValve).invoke(request, response);

    assertEquals("normalUser", argument.getValue().getName());
    final List<String> roles = Arrays.asList(argument.getValue().getRoles());
    assertEquals(2, roles.size());
    assertTrue(roles.contains("islandora"));
    assertTrue(roles.contains("http://test2.com"));
    assertNull(argument.getValue().getPassword());
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:39,代码来源:SynValveTest.java

示例12: allowGetWithoutToken

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
@Test
public void allowGetWithoutToken() throws Exception {
    final String host = "http://anon-test.com";
    final SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setAuthConstraint(true);
    when(realm.findSecurityConstraints(request, request.getContext()))
        .thenReturn(new SecurityConstraint[] { securityConstraint });
    when(request.getMethod()).thenReturn("GET");
    when(mockHost.toString()).thenReturn(host);
    when(request.getHost()).thenReturn(mockHost);

    final ArgumentCaptor<GenericPrincipal> argument = ArgumentCaptor.forClass(GenericPrincipal.class);

    final String testXml = String.join("\n"
        , "<config version='1'>"
        , "  <site url='" + host + "' algorithm='HS256' encoding='plain' anonymous='true'>"
        , "secretFool"
        , "  </site>"
        , "</config>"
    );
    Files.write(Paths.get(this.settings.getAbsolutePath()), testXml.getBytes());

    synValve.start();
    synValve.invoke(request, response);

    final InOrder inOrder = inOrder(request, nextValve);
    inOrder.verify(request).setUserPrincipal(argument.capture());
    inOrder.verify(nextValve).invoke(request, response);

    assertEquals("anonymous", argument.getValue().getName());
    final List<String> roles = Arrays.asList(argument.getValue().getRoles());
    assertEquals(2, roles.size());
    assertTrue(roles.contains("anonymous"));
    assertTrue(roles.contains("islandora"));
    assertNull(argument.getValue().getPassword());
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:37,代码来源:SynValveTest.java

示例13: allowHeadWithoutToken

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
@Test
public void allowHeadWithoutToken() throws Exception {
    final String host = "http://anon-test.com";
    final SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setAuthConstraint(true);
    when(realm.findSecurityConstraints(request, request.getContext()))
        .thenReturn(new SecurityConstraint[] { securityConstraint });
    when(request.getMethod()).thenReturn("HEAD");
    when(mockHost.toString()).thenReturn(host);
    when(request.getHost()).thenReturn(mockHost);

    final ArgumentCaptor<GenericPrincipal> argument = ArgumentCaptor.forClass(GenericPrincipal.class);

    final String testXml = String.join("\n"
        , "<config version='1'>"
        , "  <site url='" + host + "' algorithm='HS256' encoding='plain' anonymous='true'>"
        , "secretFool"
        , "  </site>"
        , "</config>"
    );
    Files.write(Paths.get(this.settings.getAbsolutePath()), testXml.getBytes());

    synValve.start();
    synValve.invoke(request, response);

    final InOrder inOrder = inOrder(request, nextValve);
    inOrder.verify(request).setUserPrincipal(argument.capture());
    inOrder.verify(nextValve).invoke(request, response);

    assertEquals("anonymous", argument.getValue().getName());
    final List<String> roles = Arrays.asList(argument.getValue().getRoles());
    assertEquals(2, roles.size());
    assertTrue(roles.contains("anonymous"));
    assertTrue(roles.contains("islandora"));
    assertNull(argument.getValue().getPassword());
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:37,代码来源:SynValveTest.java

示例14: overrideDefaultDeny

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
@Test
public void overrideDefaultDeny() throws Exception {
    final String host = "http://anon-test.com";
    final SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setAuthConstraint(true);
    when(realm.findSecurityConstraints(request, request.getContext()))
        .thenReturn(new SecurityConstraint[] { securityConstraint });
    when(request.getMethod()).thenReturn("GET");
    when(mockHost.toString()).thenReturn(host);
    when(request.getHost()).thenReturn(mockHost);

    final ArgumentCaptor<GenericPrincipal> argument = ArgumentCaptor.forClass(GenericPrincipal.class);

    final String testXml = String.join("\n"
        , "<config version='1'>"
        , "  <site url='" + host + "' algorithm='HS256' encoding='plain' anonymous='true'>"
        , "secretFool"
        , "  </site>"
        , "  <site algorithm='RS256' encoding='plain' anonymous='true' default='false'/>"
        , "</config>"
    );
    Files.write(Paths.get(this.settings.getAbsolutePath()), testXml.getBytes());

    synValve.start();
    synValve.invoke(request, response);

    final InOrder inOrder = inOrder(request, nextValve);
    inOrder.verify(request).setUserPrincipal(argument.capture());
    inOrder.verify(nextValve).invoke(request, response);

    assertEquals("anonymous", argument.getValue().getName());
    final List<String> roles = Arrays.asList(argument.getValue().getRoles());
    assertEquals(2, roles.size());
    assertTrue(roles.contains("anonymous"));
    assertTrue(roles.contains("islandora"));
    assertNull(argument.getValue().getPassword());
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:38,代码来源:SynValveTest.java

示例15: defaultAndSiteAllowed

import org.apache.catalina.realm.GenericPrincipal; //导入依赖的package包/类
@Test
public void defaultAndSiteAllowed() throws Exception {
    final String host = "http://anon-test.com";
    final SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setAuthConstraint(true);
    when(realm.findSecurityConstraints(request, request.getContext()))
        .thenReturn(new SecurityConstraint[] { securityConstraint });
    when(request.getMethod()).thenReturn("GET");
    when(mockHost.toString()).thenReturn(host);
    when(request.getHost()).thenReturn(mockHost);

    final ArgumentCaptor<GenericPrincipal> argument = ArgumentCaptor.forClass(GenericPrincipal.class);

    final String testXml = String.join("\n"
        , "<config version='1'>"
        , "  <site algorithm='RS256' encoding='plain' anonymous='true' default='true'/>"
        , "</config>"
    );
    Files.write(Paths.get(this.settings.getAbsolutePath()), testXml.getBytes());

    synValve.start();
    synValve.invoke(request, response);

    final InOrder inOrder = inOrder(request, nextValve);
    inOrder.verify(request).setUserPrincipal(argument.capture());
    inOrder.verify(nextValve).invoke(request, response);

    assertEquals("anonymous", argument.getValue().getName());
    final List<String> roles = Arrays.asList(argument.getValue().getRoles());
    assertEquals(2, roles.size());
    assertTrue(roles.contains("anonymous"));
    assertTrue(roles.contains("islandora"));
    assertNull(argument.getValue().getPassword());
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:35,代码来源:SynValveTest.java


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