Example usage for java.security Principal Principal

List of usage examples for java.security Principal Principal

Introduction

In this page you can find the example usage for java.security Principal Principal.

Prototype

Principal

Source Link

Usage

From source file:bad.robot.http.apache.OAuthAccessToken.java

@Override
public Principal getUserPrincipal() {
    return new Principal() {
        @Override//from   w  w  w. j ava  2s  .  c  o  m
        public String getName() {
            return token;
        }
    };
}

From source file:io.restassured.module.mockmvc.SecuredControllerTest.java

@Test
public void javax_principal_authentication_works() {
    RestAssuredMockMvc.given().standaloneSetup(new SecuredController()).auth().principal(new Principal() {
        public String getName() {
            return "authorized_user";
        }/*from   ww  w  .  ja v a 2s  . c om*/
    }).param("name", "Johan").when().get("/principalGreeting").then().statusCode(200).body("content",
            equalTo("Hello, Johan!"));
}

From source file:com.jayway.restassured.module.mockmvc.SecuredControllerTest.java

@Test
public void javax_principal_authentication_works() {
    given().standaloneSetup(new SecuredController()).auth().principal(new Principal() {
        public String getName() {
            return "authorized_user";
        }/*from  www. j  av  a2 s  .  c  om*/
    }).param("name", "Johan").when().get("/principalGreeting").then().statusCode(200).body("content",
            equalTo("Hello, Johan!"));
}

From source file:org.bremersee.common.security.core.context.RunAsAuthentication.java

@Override
public Object getPrincipal() {
    return new Principal() {
        @Override/*from w ww.j  a  v a 2 s .  c  o m*/
        public String toString() {
            return getName();
        }

        @Override
        public String getName() {
            return name;
        }
    };
}

From source file:org.jasig.cas.adaptors.trusted.web.flow.PrincipalFromRequestUserPrincipalNonInteractiveCredentialsActionTests.java

public void testRemoteUserExists() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setUserPrincipal(new Principal() {
        public String getName() {
            return "test";
        }/*  w ww.  ja  v  a2s.  c  om*/
    });

    final MockRequestContext context = new MockRequestContext();
    context.setExternalContext(
            new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));

    assertEquals("success", this.action.execute(context).getId());
}

From source file:com.jayway.restassured.module.mockmvc.SecuredControllerTest.java

@Test
public void statically_defined_authentication_works() {
    // Given//from   w  ww.  j  av  a2 s. c o m
    RestAssuredMockMvc.authentication = principal(new Principal() {
        public String getName() {
            return "authorized_user";
        }
    });

    // When
    try {
        given().standaloneSetup(new SecuredController()).param("name", "Johan").when().get("/principalGreeting")
                .then().statusCode(200).body("content", equalTo("Hello, Johan!"));
    } finally {
        RestAssuredMockMvc.reset();
    }
}

From source file:io.restassured.module.mockmvc.SecuredControllerTest.java

@Test
public void statically_defined_authentication_works() {
    // Given/*www  .jav  a 2  s  .co  m*/
    RestAssuredMockMvc.authentication = RestAssuredMockMvc.principal(new Principal() {
        public String getName() {
            return "authorized_user";
        }
    });

    // When
    try {
        RestAssuredMockMvc.given().standaloneSetup(new SecuredController()).param("name", "Johan").when()
                .get("/principalGreeting").then().statusCode(200).body("content", equalTo("Hello, Johan!"));
    } finally {
        RestAssuredMockMvc.reset();
    }
}

From source file:com.qwazr.connectors.TableRealmConnector.java

@Override
public Account verify(String id, Credential credential) {

    // This realm only support one type of credential
    if (!(credential instanceof PasswordCredential))
        throw new RuntimeException("Unsupported credential type: " + credential.getClass().getName());

    PasswordCredential passwordCredential = (PasswordCredential) credential;

    // We request the database
    final LinkedHashMap<String, Object> row;
    try {/*  w  w w .  ja v a 2  s. c o  m*/
        row = tableService.getRow(table_name, id, columns);
        if (row == null)
            return null;
    } catch (WebApplicationException e) {
        if (e.getResponse().getStatusInfo().getFamily() == Response.Status.Family.CLIENT_ERROR)
            return authenticationFailure("Unknown user: " + id);
        throw e;
    }

    Object password = row.get(password_column);
    if (password == null)
        return null;
    if (password instanceof String[]) {
        String[] passwordArray = (String[]) password;
        if (passwordArray.length == 0)
            return null;
        password = passwordArray[0];
    }

    // The password is stored hashed
    final String passwd = new String(passwordCredential.getPassword());
    String digest = DigestUtils.sha256Hex(passwd);
    if (!digest.equals(password))
        return authenticationFailure("Wrong password: " + id + " " + digest + '/' + passwd + '/' + password);

    //We retrieve the roles
    Object object = row.get(roles_column);
    LinkedHashSet<String> roles = new LinkedHashSet<String>();
    if (object instanceof String[]) {
        for (Object o : (String[]) object)
            roles.add(o.toString());
    } else
        roles.add(object.toString());

    return new Account() {
        @Override
        public Principal getPrincipal() {
            return new Principal() {
                @Override
                public String getName() {
                    return id;
                }
            };
        }

        @Override
        public Set<String> getRoles() {
            return roles;
        }
    };
}

From source file:com.jayway.restassured.module.mockmvc.SecuredControllerTest.java

@Test
public void can_override_static_auth_config_with_none() {
    exception.expectMessage("Not authorized");

    // Given//from  ww  w  .  j  av a2  s.c om
    RestAssuredMockMvc.authentication = principal(new Principal() {
        public String getName() {
            return "authorized_user";
        }
    });

    // When
    try {
        given().standaloneSetup(new SecuredController()).auth().none().param("name", "Johan").when()
                .get("/principalGreeting");
    } finally {
        RestAssuredMockMvc.reset();
    }
}

From source file:io.restassured.module.mockmvc.SecuredControllerTest.java

@Test
public void can_override_static_auth_config_with_none() {
    exception.expectMessage("Not authorized");

    // Given/*from   w  w w  .j a v a 2 s. com*/
    RestAssuredMockMvc.authentication = RestAssuredMockMvc.principal(new Principal() {
        public String getName() {
            return "authorized_user";
        }
    });

    // When
    try {
        RestAssuredMockMvc.given().standaloneSetup(new SecuredController()).auth().none().param("name", "Johan")
                .when().get("/principalGreeting");
    } finally {
        RestAssuredMockMvc.reset();
    }
}